
package com.ukao.pad.presenter;

import android.content.Context;

import com.ukao.pad.base.BasePresenter;
import com.ukao.pad.bean.FactoryBatchInBean;
import com.ukao.pad.bean.PrintAloneBean;
import com.ukao.pad.bean.ProductBatchInBean;
import com.ukao.pad.bean.StringBean;
import com.ukao.pad.consts.Constant;
import com.ukao.pad.consts.SaveParamets;
import com.ukao.pad.retrofit.ApiCallback;
import com.ukao.pad.utils.L;
import com.ukao.pad.utils.Utils;
import com.ukao.pad.view.LeverFactoryView;

import java.util.HashMap;

import static android.R.attr.id;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class LeverFactoryPesenter extends BasePresenter<LeverFactoryView> {



    public LeverFactoryPesenter(LeverFactoryView view) {
        attachView(view);
    }



    /*离厂 左边*/
    public void createBatchOut1( String  outId  ,boolean isshowdialog ) {
        if (isshowdialog){
            mvpView.showLoading();
        }
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("outId",outId);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.createBatchOut1(Constant.createParameter(mHashMap)),
                new ApiCallback<ProductBatchInBean>() {
                    @Override
                    public void onSuccess(ProductBatchInBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadbatchListSuccess(model.getData(),"");

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.refreshFinish();
                        mvpView.hideLoading();
                    }
                });
    }





    /*离厂 右边*/
    public void createBatchOut(final String  batchCode,boolean isshowdialog  ) {
        if (isshowdialog){
            mvpView.showLoading();
        }

        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("scanCode",batchCode);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        L.i("scanCode");
        addSubscription(apiStores.createBatchOut(Constant.createParameter(mHashMap)),
                new ApiCallback<ProductBatchInBean>() {
                    @Override
                    public void onSuccess(ProductBatchInBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadbatchListSuccess(model.getData(),batchCode);

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.refreshFinish();
                        mvpView.hideLoading();
                    }
                });
    }

    /*离厂  左边   参数id*/
    public void detailleft1( String  id  ) {

        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("id",id);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.detailleft1(Constant.createParameter(mHashMap)),
                new ApiCallback<FactoryBatchInBean>() {
                    @Override
                    public void onSuccess(FactoryBatchInBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadDetailleftData(model.getData());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {


                    }
                });
    }






    /*离厂  左边   衣物条码*/
    public void detailleft( String  detailByCode  ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("code",detailByCode);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.detailleft(Constant.createParameter(mHashMap)),
                new ApiCallback<FactoryBatchInBean>() {
                    @Override
                    public void onSuccess(FactoryBatchInBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadDetailleftData(model.getData());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }
                });
    }





    /*工厂上报缺失*/
    public void loseLeaveFactory( String  ids,String  outId  ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("ids",ids);
        mHashMap.put("outId",outId);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.loseLeaveFactory(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loseFactorySuccess(model.getMsg());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }


    /*確定出厂　参数*/
    public void sureLeaveFactory(Context context, String  id ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("id",id);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.leaveComplete(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.sureFactorySuccess();

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }

    /*工厂已全部核对*/
    public void checkAllConfirmProFactory(Context context, String  id ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("outId",id);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.checkAllConfirmProFactory(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.checkAllFactory(model.getMsg());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }
    /*打印衣物清单　参数*/
    public void printbatchOut(String  id ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("id",id);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.printbatchOut(Constant.createParameter(mHashMap)),
                new ApiCallback<PrintAloneBean>() {
                    @Override
                    public void onSuccess(PrintAloneBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadPrintbatchOutSuccess(model.getData());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }


    /**
     * 批量删除出厂衣物
     * @param ids  批次衣物关联id列表格式 [id,id,id]

     */
    public void deleteBatch(String  ids ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("ids",ids);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.deleteBatch(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.deleteSucceed();
                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }



}
